package com.uu.custom.yingbang.facade.restful;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.uu.custom.yingbang.facade.restful.model.SelectTrackRequest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @Author LiuKe
 * @Date 2017/9/20 20:59
 */

public class RestfulUtil {
    public static String post(String url , Map<String,String> map){
        RestTemplate restTemplate = new RestTemplate();
        MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
        for(String key : map.keySet()){
            requestEntity.add(key,map.get(key));
        }
        return restTemplate.postForObject(url,requestEntity,String.class);
    }
    public static String get(String url , Map<String,String> request){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        return restTemplate.getForObject(url, String.class, request);
    }
}
